// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   LoginUserFilter.java

package com.hfstu.pms.web.filter;

import com.hfstu.pms.dto.UserDTO;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoginUserFilter
	implements Filter
{

	private Logger log;
	private String redirectURl;

	public LoginUserFilter()
	{
		log = LoggerFactory.getLogger(com/hfstu/pms/web/filter/LoginUserFilter);
		redirectURl = null;
	}

	public void destroy()
	{
		redirectURl = null;
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
		throws IOException, ServletException
	{
		HttpServletRequest request = (HttpServletRequest)servletRequest;
		HttpServletResponse response = (HttpServletResponse)servletResponse;
		StringBuffer url = new StringBuffer(request.getRequestURI());
		log.info((new StringBuilder("uri = ")).append(url).toString());
		request.getQueryString();
		if (!url.toString().endsWith("login.jsp"))
		{
			HttpSession session = request.getSession();
			UserDTO user = (UserDTO)session.getAttribute("v_user");
			if (user == null)
			{
				String path = request.getContextPath();
				String basePath = (new StringBuilder(String.valueOf(request.getScheme()))).append("://").append(request.getServerName()).append(":").append(request.getServerPort()).append(path).append("/").toString();
				request.setCharacterEncoding("UTF-8");
				response.getOutputStream().print((new StringBuilder("<script>window.top.location.href='")).append(basePath).append(redirectURl).append("';</script>").toString());
				return;
			}
		}
		filterChain.doFilter(servletRequest, servletResponse);
	}

	public void init(FilterConfig filterConfig)
		throws ServletException
	{
		redirectURl = filterConfig.getInitParameter("relogin");
	}
}
